/* UI
*/

		Include("data/scripts/locale.nut")

g_ui_IDs	<-	0

function	CreateNewUIID()
{
	return g_ui_IDs
	g_ui_IDs++
}

function	UICommonSetup()
{
	UILoadFont ("data/ui/aerial.ttf")
}

function	CreateLabel(ui, name, x, y, size = 32, w = 200, h = 64)
{
	// Create UI window.
	local	window = UIAddWindow(ui, -1, x, y, w, h)

	// Center window pivot.
	//WindowSetPivot(window, w / 2, h / 2)

	// Create UI text widget and set as window base widget.
	local	widget = UIAddStaticTextWidget(ui, -1, name, "aerial")
	WindowSetBaseWidget(window, widget)

	// Set text attributes.
	TextSetSize(widget, size)
	TextSetColor(widget, 255, 255, 255, 255)
	TextSetAlignment(widget, TextAlignLeft)

	// Return window.
	return [ window, widget ]
}


class	HudUI
{
//	ui						= 0
	
	power_gauge				= 0
	shield_gauge			= 0
	room_name				= 0

	inventory_bitmaps		= 0
	
	function	ui()
	{	return	SceneGetUI(g_scene)	}

	constructor()
	{		
		print("HudUI::Setup()")
//		ui = _ui
		UICommonSetup()
		power_gauge = CreatePowerGauge()
		shield_gauge = CreateShieldGauge()
		room_name = CreateRoomName()
		inventory_bitmaps = []
	}

	function	UpdateInventory(inventory)
	{
		local	x,y
		local	i, new_bitmap

		x = 650.0
		y = 8.0


		foreach(i in inventory_bitmaps)
			UIDeleteWindow(ui(), i)


		inventory_bitmaps = []

		foreach(i in inventory.item_list)
		{
			new_bitmap = UIAddBitmapWindow(ui(), -1, "data/maps/keys/" + i + ".tga", x, y, 256, 256)
			WindowSetScale(new_bitmap, 0.175, 0.175)
			inventory_bitmaps.append(new_bitmap)
			x += 32
		}
	}

	function	UpdatePowerGauge(v)
	{		//TextSetText(power_gauge[1], CreateGaugeBar(v))	
	}

	function	UpdateShieldGauge(v)
	{		//TextSetText(shield_gauge[1], CreateGaugeBar(v))	
	}

	function	UpdateRoomName(name)
	{		//TextSetText(room_name[1], name)	
	}

	function	CreateGaugeBar(n)
	{
		n = (n.tofloat() / 10.0).tointeger()
		local i, str
		str = ""
		for(i = 0; i < n; i++)
			str += "|"

		return str
	}
	
	function	CreateRoomName()
	{
		print("HudUI::CreateRoomName()")
		local	_name = CreateLabel(ui(), "Room Name", 0, 960 - 64, 32, 1024, 64)
		return _name
	}

	function	CreatePowerGauge()
	{
		print("HudUI::CreatePowerGauge()")

		CreateLabel(ui(), g_locale.hud_power, 310 + 0, 0)
		local	_gauge	= CreateLabel(ui(), CreateGaugeBar(100), 310 + 170, 0)
		return _gauge
	}

	function	CreateShieldGauge()
	{
		print("HudUI::CreatePowerGauge()")

		CreateLabel(ui(), g_locale.hud_shield, 0, 0)
		local	_gauge	= CreateLabel(ui(), CreateGaugeBar(100), 170, 0)
		return _gauge
	}
}